<?php


    if(isset($_FWORK)) {
        die("Framework must not be initialised multiple times.");
    }
    
    // ----- Begin Buffering Output ----- //
    ob_start();
    
    // ----- Framework Definitions ----- //
    $_FWORK = array();
    define('E_NONE', 0);
    
    // ----- Framework Options ----- //
    $_FWORK['SETTINGS']['FW_ROOT'] = realpath(__DIR__).'/';
    
    // ----- Framework Modules On/Off ----- //
    $_FWORK['MODULES']['LIBDEBUG'] = true;
    $_FWORK['MODULES']['SQL_CON'] = true;
    $_FWORK['MODULES']['UTILITIES'] = true;
    $_FWORK['MODULES']['USE_REGISTRY'] = false;
    $_FWORK['MODULES']['DEBUGGER'] = true;
    $_FWORK['MODULES']['VERBOSITY'] = false;
    
    
    // ----- libDebug Module ----- //
    if($_FWORK['MODULES']['LIBDEBUG'] === true) {
	$_FWORK['LIBDEBUG']['LOG_MODE'] = 'SCREEN'; // Valid Options: SCREEN | DATABASE | BOTH | NONE | DEBUG
	$_FWORK['LIBDEBUG']['E_REPORTING'] = E_ALL; // Valid Options: E_ALL, E_NONE, E_STRICT  etc [ see: error_reporting() ]
	require_once($_FWORK['SETTINGS']['FW_ROOT'].'libDebug/libDebug.php');
	
	if($_FWORK['LIBDEBUG']['LOG_MODE'] == "SCREEN") {
	    $to_screen = true;
	    $to_db = false;
	    $perm_out = false;
	} elseif($_FWORK['LIBDEBUG']['LOG_MODE'] == "DATABASE") {
	    $to_screen = false;
	    $to_db = true;
	    $perm_out = false;
	} elseif($_FWORK['LIBDEBUG']['LOG_MODE'] == "BOTH") {
	    $to_screen = true;
	    $to_db = true;
	    $perm_out = false;
	} elseif($_FWORK['LIBDEBUG']['LOG_MODE'] == "DEBUG") {
	    $to_screen = true;
	    $to_db = false;
	    $perm_out = true;
	} else {
	    $to_screen = false;
	    $to_db = false;
	    $perm_out = false;
	}
	
	$_LIBDEBUG = new libDebug($to_screen, $to_db, $perm_out);
	set_error_handler(array(&$_LIBDEBUG, "error_handler"), E_ALL);
        set_exception_handler(array(&$_LIBDEBUG, "excep_handler"));
    }
    
    // ----- MySQL Connection Module ----- //
    if($_FWORK['MODULES']['SQL_CON'] === true) {
	require_once($_FWORK['SETTINGS']['FW_ROOT'].'MySQL/configuration.php');
	require_once($_FWORK['SETTINGS']['FW_ROOT'].'MySQL/makeConnection.php');
	// Security: Unset Variables Containing Passwords and Information //
	unset($_FWORK['MYSQL_CONF']);
    }
    
    // ----- Utilities ----- //
    // This is used in many places, so we will have it regardless
    require_once($_FWORK['SETTINGS']['FW_ROOT'].'utilities/Exceptions.php');
    if($_FWORK['MODULES']['UTILITIES'] === true) {
	/* :::::    Comment Out Un-needed files
	 * Note:    Order Matters!!! example: Crypto is dependent on Singleton!
	 */
	require_once($_FWORK['SETTINGS']['FW_ROOT'].'utilities/Singleton.php');
	require_once($_FWORK['SETTINGS']['FW_ROOT'].'utilities/Crypto.php');
	require_once($_FWORK['SETTINGS']['FW_ROOT'].'utilities/autoPOSTGET.php');
    }
    
    // ----- Registry ----- //
    if($_FWORK['MODULES']['USE_REGISTRY'] === true) {
	require_once($_FWORK['SETTINGS']['FW_ROOT'].'registry/Registry.php');
    }
    
    // ----- Debugger ----- //
    if($_FWORK['MODULES']['DEBUGGER'] === true) {
	require_once($_FWORK['SETTINGS']['FW_ROOT'].'debugger/debugger.php');
    }
    
    if($_FWORK['MODULES']['VERBOSITY'] === true) {
	if(isset($_SERVER['REDIRECT_URL']) === true) {
	    trigger_error('[v] REDIRECT_URL: '.$_SERVER['REDIRECT_URL']);
	}
	if(isset($_SERVER['QUERY_STRING']) === true) {
	    trigger_error('[v] QUERY_STRING: '.$_SERVER['QUERY_STRING']);
	}
    }
?>
